<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="css/main.css"/>
	</head>

	<body>
		<script src="js/mui.min.js"></script>
		<script type="text/javascript">
			mui.init()
		</script>
		<header class="mui-bar mui-bar-nav">
		    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
		    <h1 class="mui-title"></h1>
		</header>
		<div class="mui-content">
		    <div id="msg">此处为聊天消息</div>
		<button type="button" id="grallery" class="mui-btn mui-btn-green">相册</button>
		<button type="button" id="carmera" class="mui-btn mui-btn-blue">摄像头</button>
		<button type="button" id="getacc" class="mui-btn mui-btn-yellow">传感器</button>
		</div>
		
	</body>

</html>
<script type="text/javascript">
	mui.plusReady(function(){
		var cw=plus.webview.currentWebview();
		var titleName=cw.title;
		var header= document.querySelector(".mui-title");
		header.innerText=titleName;
	})
	//展示通过id单个绑定,选择一张照片
	/*var msgDom=document.getElementById("msg");
	var garreyButton=document.getElementById("grallery");
	garreyButton.addEventListener("tap",function(e){
		plus.gallery.pick(function(path){
			var img="<img width=100 height=100 src="+path+">";
			msgDom.innerHTML=img;
			
		})
	})*/
	//多张图片的获取，oppo上必须长按，才能进行选择
	var msgDom=document.getElementById("msg");
	var garreyButton=document.getElementById("grallery");
	garreyButton.addEventListener("tap",function(e){
		plus.gallery.pick(function(path){
			alert(path.files.length);
			var img="";
			
			for(var i in path.files){
				img+="<img width=100 height=100 src="+path.files[i]+">";
				alert(path.files[i]);
			}
				msgDom.innerHTML=img;
		},
		function(e){
			msgDom.innerHTML=e.message;
		},
		{
			filter:"image",
			multiple:true
		})
	}) 
	var cmDom=document.getElementById("carmera");
	cmDom.addEventListener("tap",function(e){
		var cm=plus.camera.getCamera(1);
		cm.captureImage(function(path){
			var url="file://"+plus.io.convertLocalFileSystemURL(path);
			var img="<img width=100 height=100 src="+url+">";
			msgDom.innerHTML=img;
		});
	});
	//调用传感器
	var accDom=document.getElementById("getacc");
	accDom.addEventListener("tap",function(e){
//		plus.accelerometer.getCurrentAcceleration(function(a){
//			var msg=document.getElementById("msg");
//			msg.innerText="x:"+a.xAxis+"\n y:"+a.yAxis+"\n z"+a.zAxis;
//			
//		})
       plus.accelerometer.watchAcceleration(function(a){
       		var msg=document.getElementById("msg");
			msg.innerText="x:"+a.xAxis+"\n y:"+a.yAxis+"\n z"+a.zAxis;
       })
	});
	
</script>